package com.comyou.beacon;

import android.bluetooth.BluetoothDevice;

import com.comyou.beacondemo.CYUtils;

public class BeaconClass {
	
	
	static public class Beacon{
		public String name;
		public int major;
		public int minor;
		public String uuid;
		public BluetoothDevice device;

		public int rssi;
		
		
		@Override
		public String toString() {
			 
			return " uuid:"+uuid+" major:"+major+" minor:"+minor;
		}

	}
	
	
	public static Beacon fromScanData( byte[] scandata,BluetoothDevice bluetoothdeivce, int rssi){
		
		if(scandata[7]==0x02&&scandata[8]==0x15) {

			
			byte[] uuidValue=new byte[16];
			System.arraycopy(scandata, 9, uuidValue, 0, 16);

			
			String uuid="";
			String hexStr=CYUtils.Bytes2HexString(uuidValue);
			
			uuid=hexStr.substring(0, 8);
			uuid+="-";
			uuid+=hexStr.substring(8, 12);
			uuid+="-";
			uuid+=hexStr.substring(12, 16);
			uuid+="-";
			uuid+=hexStr.substring(16, 20);
			uuid+="-";
			uuid+=hexStr.substring(20, 32);

			int major=CYUtils.byteToInt(scandata[25], scandata[26]);
			int minor=CYUtils.byteToInt(scandata[27], scandata[28]);
			

			Beacon beacon=	new Beacon();
			beacon.uuid=uuid;
			beacon.major=major;
			beacon.minor=minor;
			beacon.name=bluetoothdeivce.getName();
			beacon.device=bluetoothdeivce;
			beacon.rssi=rssi;
			
			return beacon;
			
		}else{

			return null;
				
		}
		
	}
	
}
